#ifndef __stream_H
#define __stream_H

#ifdef __cplusplus
extern "C"
{
#endif

#include "sys.h"
#include <stdint.h>

#if ENABLE_OS_SUPPORT
#include "FreeRTOS.h"
#include "semphr.h"
#endif

#define SERIAL_PAYLOAD_SIZE 256
#define SERIAL_BUFFER_SIZE 512

    typedef struct Serial
    {
        uint8_t *payload;
        uint8_t *buffer;
        uint16_t size;
#if ENABLE_OS_SUPPORT
        SemaphoreHandle_t rx_complete;
        SemaphoreHandle_t tx_complete;
#else
    volatile uint8_t rx_complete;
    volatile uint8_t tx_complete;
#endif
        void *arg;
        void (*RecvCallback)(struct Serial *handle);
        void (*SendCallback)(struct Serial *handle, uint8_t *data, uint16_t size);
    } serial_t;

    typedef serial_t *serial_handle_t;

    typedef void (*serial_recv_cb_t)(serial_handle_t handle);
    typedef void (*serial_send_cb_t)(serial_handle_t handle, uint8_t *data, uint16_t size);

    serial_handle_t Serial_Init(void *arg, serial_recv_cb_t recv_cb, serial_send_cb_t send_cb);
    void Serial_DeInit(serial_handle_t handle);
    void Serial_Run(serial_handle_t handle);
    void Serial_Print(serial_handle_t handle, uint8_t *data, uint16_t size);
    void Serial_Printf(serial_handle_t handle, const char *format, ...);
    void Serial_SendComplete(serial_handle_t handle);
    void Serial_RecvComplete(serial_handle_t handle, uint16_t size);

#ifdef __cplusplus
}
#endif

#endif